﻿
Imports std
Imports name_property = osi.fs.cached_string_property
Imports time_property = osi.fs.cached_int64_property
Imports text_property = osi.fs.string_property

Partial Public Class node
    Partial Private Class internal_property_names
        Public Const name As String = "nam"
        Public Const create_time As String = "ctm"
        Public Const last_write_time As String = "wtm"
        Public Const text As String = "txt"
    End Class

    Private Shared Function now_time() As Int64
        Return Now.milliseconds()
    End Function

    Public Function name(ByVal output As pointer(Of name_property)) As eventComb
        Return p.get(Of String, name_property)(internal_property_names.name, output)
    End Function

    Public Function name(ByVal output As pointer(Of String)) As eventComb
        Return p.get_data(internal_property_names.name, output)
    End Function

    Public Function set_name(ByVal v As String) As eventComb
        Return p.create_set_data(Of String, name_property)(internal_property_names.name, v)
    End Function

    Public Function create_time(ByVal output As pointer(Of Int64)) As eventComb
        Return p.get_data(internal_property_names.create_time, output)
    End Function

    Private Sub ensure_create_time()
        assert_begin(p.create_get_set_data(Of Int64, time_property) _
                                          (internal_property_names.create_time,
                                           Function(ByRef x As Int64) As Boolean
                                               If x = 0 Then
                                                   x = now_time()
                                               End If
                                               Return True
                                           End Function))
    End Sub

    Public Function last_write_time(ByVal output As pointer(Of Int64)) As eventComb
        Return p.get_data(internal_property_names.last_write_time, output)
    End Function

    Private Function set_last_write_time() As eventComb
        Return p.create_set_data(Of Int64, time_property)(internal_property_names.last_write_time, now_time())
    End Function

    Public Function text(ByVal output As pointer(Of text_property)) As eventComb
        Return p.get(Of String, text_property)(internal_property_names.text, output)
    End Function

    Public Function text(ByVal output As pointer(Of String)) As eventComb
        Return p.get_data(internal_property_names.text, output)
    End Function

    Public Function set_text(ByVal value As String) As eventComb
        Return p.create_set_data(Of String, text_property)(internal_property_names.text, value)
    End Function
End Class
